package sgd.tp2.api.cdr;

import java.util.StringTokenizer;

public class CDRHandlerCSV implements ICDRHandler {
	
	public static final char DELIMITER = ',';

	public static String getCSVFromCDR(CDR record) {

		char d = DELIMITER;

		return record.getCallerId() + d + record.getDuration() + d
				+ record.getBillSec() + d + record.getProgressSec() + d
				+ record.getProgressMediaSec() + d + record.getFlowBillSec()
				+ d + record.getmDuration() + d + record.getBillMSec() + d
				+ record.getProgressMSec() + d + record.getProgressMediaMSec()
				+ d + record.getFlowBillMSec() + d + record.getuDuration();
	}
	
	public static CDR getCDRFromCSV(String csv) {
		StringTokenizer strTok = new StringTokenizer(csv, DELIMITER+"");
		
		CDR cdr = new CDR();
		
		cdr.setCallerId(strTok.nextToken());
		cdr.setDuration(Integer.parseInt(strTok.nextToken()));
		cdr.setBillSec(Integer.parseInt(strTok.nextToken()));
		cdr.setProgressSec(Integer.parseInt(strTok.nextToken()));
		cdr.setProgressMediaSec(Integer.parseInt(strTok.nextToken()));
		cdr.setFlowBillSec(Integer.parseInt(strTok.nextToken()));
		cdr.setmDuration(Long.parseLong(strTok.nextToken()));
		cdr.setBillMSec(Long.parseLong(strTok.nextToken()));
		cdr.setProgressMSec(Long.parseLong(strTok.nextToken()));
		cdr.setProgressMediaMSec(Long.parseLong(strTok.nextToken()));
		cdr.setFlowBillMSec(Long.parseLong(strTok.nextToken()));
		cdr.setuDuration(Long.parseLong(strTok.nextToken()));
		
		return cdr;
	}
}
